﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BGMManager : Singleton<BGMManager>
{
    public AudioSource audioSource;
    public AudioClip bgmClip;
    public override void Init()
    {
        base.Init();
        if (!audioSource)
        {
            audioSource = this.gameObject.AddComponent<AudioSource>();
            audioSource.volume = 0.8f;
        }
    }
    public void PlayBGM(string clipName)
    {
        if (audioSource != null)
        {
            if (!audioSource.isPlaying)
            {
                bgmClip = Resources.Load<AudioClip>("AudioClip/" + clipName);
                AudioManager.Instance.PlayBGM(audioSource, bgmClip);
            }
        }
    }
    public void StopBGM()
    {
        if (audioSource != null)
        {
            AudioManager.Instance.StopBGM(audioSource);
        }
    }
    public void ResumeBGM(string clipName = null)
    {
        if (clipName != null)
        {
            bgmClip = Resources.Load<AudioClip>("AudioClip/" + clipName);
        }
        if (audioSource != null)
        {
            AudioManager.Instance.ResumeBGM(audioSource, bgmClip);
        }
    }
}
